package com.zjc.lib_core.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.jwenfeng.library.pulltorefresh.BaseRefreshListener;
import com.zjc.lib_core.mvp.presenter.IPresenter;
import com.zjc.lib_core.mvp.view.IView;

import javax.inject.Inject;

/**
 * fragment封装
 * */
public abstract class BaseFragment<P extends IPresenter> extends Fragment implements IFragment, IView {

    protected int page = 1;

    @Inject
    protected P p;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = createView(inflater);
        setupDagger();
        init(view);
        initData();
        return view;
    }

    @Override
    public void onDestroy() {
        if (p != null){
            p.destroy();
        }
        p = null;
        super.onDestroy();
    }

    @Override
    public void showMsgsage(String msg) {
        Toast.makeText(getActivity(), msg , Toast.LENGTH_SHORT).show();
    }

}
